const app = getApp();
const _requsetCYZ = require('../../../utils/requestData');
const _functionCYZ = require('../../../utils/common');
Page({
  data: {
    this_cms_config: null,
    this_cms_index_ad_top: null,
    this_cms_index_ad_icon: null,
    this_index_top_news: null,
    this_index_rmp_news: null,
    this_data_share_title: '',
    this_data_share_img: '',
    showSearch: false,
    inputShowed: false,
    talks:''
  },
  onLoad: function(op) {
    var that = this;
    that.get_index_data();
  },
  get_index_data: function() {
    var that = this;
    _functionCYZ.CYZ_loading();
    var requestData = {};
    _requsetCYZ.cyz_requestGet('/WuliuCmsApiIndex/index', requestData, function(cyz_data) {
      wx.hideToast();
      if (cyz_data.code == 1) {
        that.setData({
          this_cms_config: cyz_data.info.this_cms_config,
          this_cms_index_ad_top: cyz_data.info.this_cms_index_ad_top,
          this_cms_index_ad_icon: cyz_data.info.this_cms_index_ad_icon,
          this_index_top_news: cyz_data.info.this_index_top_news,
          this_index_rmp_news: cyz_data.info.this_index_rmp_news
        });
        if (cyz_data.info.this_cms_config.is_open_query == 1){
           that.setData({showSearch:true});
        }
        if (cyz_data.info.this_cms_config != null) {
          wx.setNavigationBarTitle({
            title: cyz_data.info.this_cms_config.cms_title
          });
          that.setData({
            this_data_share_title: cyz_data.info.this_cms_config.share_title,
            this_data_share_img: cyz_data.info.this_cms_config.share_img
          })
        }
      } else if (cyz_data.code == 2) {
        app.getUserDataToken(function(token) {
          that.get_index_data();
        });
        return false;
      }
    });
  },
  /**
   * 跳转页面
   */
  onAppNavigateTap: function(e) {
    const dataset = e.detail.target ? e.detail.target.dataset : e.currentTarget.dataset;
    const url = dataset.url,
      appurl = dataset.appurl,
      atype = dataset.atype || 1,
      appId = dataset.appid;
    if (atype == 1) {
      if (url == '') return false;
      wx.navigateTo({
        url: url,
        fail: () => {
          wx.switchTab({
            url: url,
          });
        }
      });
    } else if (atype == 2) {
      wx.navigateToMiniProgram({
        appId: appId,
        path: appurl
      });
    } else if (atype == 3) {
      // 拨打电话
      const mobile = url;
      wx.makePhoneCall({
        phoneNumber: mobile,
      });
    }
  },
// 实时监测input框的值
  talk: function (e) {
    this.setData({
      talks: e.detail.value
    })
  },
  searchInput:function(e){
    var search_content=this.data.talks;
    wx.navigateTo({
      url: '/pages/wuliucms/chaxun/chaxun?search_content=' + search_content,
    });
  },
  onPullDownRefresh: function() {
    var that = this;
    that.get_index_data();
    setTimeout(() => {
      wx.stopPullDownRefresh()
    }, 1000);
  },
  onShareAppMessage: function() {
    var that = this;
    var sharePath = 'pages/wuliucms/index/index';
    return {
      title: that.data.this_data_share_title || '物流公司',
      path: sharePath
    }
  }
})